package com.example.xjy.zyfypt_407xjy.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.xjy.zyfypt_407xjy.R;
import com.example.xjy.zyfypt_407xjy.iface.RegisterListener;
import com.example.xjy.zyfypt_407xjy.model.RegisterModel;

public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {
    private EditText etuser,etpass,ettel;
    private Button btreg,btback;
    RegisterListener registerListener=new RegisterListener() {
        @Override
        public void onResponse(String msg) {
            if(msg.equals("1")){
                System.out.println("result:"+msg);
                finish();
            }else{
                System.out.println("result:"+msg);
            }

        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(RegisterActivity.this, msg, Toast.LENGTH_SHORT).show();
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        init();
    }
    private void init() {
        etuser = (EditText)findViewById(R.id.username);
        etpass = (EditText)findViewById(R.id.password);
        ettel = (EditText)findViewById(R.id.telephone);
        btreg = (Button)findViewById(R.id.regbutton);
        btback = (Button)findViewById(R.id.backbutton);
        btreg.setOnClickListener(this);
        btback.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.regbutton:
                System.out.println("注册——提交");
                RegisterModel registerModel = new RegisterModel();
                registerModel.getResult(etuser.getText().toString(),etpass.getText().toString(), ettel.getText().toString(), registerListener);
                break;
            case R.id.backbutton:
                Intent intent=new Intent(RegisterActivity.this,LoginActivity.class);
                startActivity(intent);
                finish();
                break;
        }
    }
}
